<?php
class Sosweb_Util_Sql_StringTools
{
	public $NUM_TYPE = 1;
	public $CHAR_TYPE = 2;
	
	public static function splitToArray($data = null, $key, $delimiter, $dataType)
	{
		$result = null;
		
		if($data != null)
		{
			foreach ($data as $id => $d):
				if($d->$key != null)
				{
					if($dataType == $this->NUM_TYPE)
						$result .= $d->$key.$delimiter;
					else
						$result .= "'".$d->$key."'".$delimiter;
				}
			endforeach;
			
			if(strlen($result) > 0)
			{
				$result = substr($result, 0, strlen($result)-1);
			}
			
			return $result;
		}
		else
		{
			return null;
		}
	}
	
	public static function getSqlState($exception)
	{
		$sqlState = substr($exception, stripos($exception, '[')+1, 5);

		return $sqlState;
	}
}